package net.hctek.AnnouncerStation.action;
	
import java.net.InetAddress;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.util.Properties;

import javax.servlet.http.HttpServletResponse;

import org.apache.struts2.ServletActionContext;
import org.hyperic.sigar.CpuInfo;
import org.hyperic.sigar.CpuPerc;
import org.hyperic.sigar.Sigar;
import org.springframework.beans.factory.annotation.Autowired;


import com.opensymphony.xwork2.ActionSupport;

import net.hctek.AnnouncerStation.bean.User;
import net.hctek.AnnouncerStation.service.IdentityServiceI;
import net.hctek.AnnouncerStation.util.Contant;
import net.hctek.AnnouncerStation.util.CookieUtils;
import net.hctek.AnnouncerStation.util.MD5;
import net.hctek.AnnouncerStation.util.ResponseJsonUtils;
import net.hctek.AnnouncerStation.util.SigarUtil;
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;

public class StatisticsAction extends ActionSupport{
	

	private static final long serialVersionUID = 1L;
	

	@Autowired
	private IdentityServiceI identityService;
	
	//查询所以用户
	public String UserCount(){
		HttpServletResponse response = ServletActionContext.getResponse();
		response.setHeader("Access-Control-Allow-Origin", "*");
		try {
			Long userCount= identityService.UserCount();
            ResponseJsonUtils.json(response,userCount);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return NONE;
	}
	
	public String NewUserCount(){
		HttpServletResponse response = ServletActionContext.getResponse();
		response.setHeader("Access-Control-Allow-Origin", "*");
		try {
			SimpleDateFormat bartDateFormat = new SimpleDateFormat
	  				("yyyy-MM-dd"); 
			Date date = new Date(); 
			System.out.println(bartDateFormat.format(date)); 
			Long newUserCount = identityService.NewUserCount(bartDateFormat.format(date));
			ResponseJsonUtils.json(response,newUserCount);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return NONE;
	}
	
	public String NewSongCount(){
		HttpServletResponse response = ServletActionContext.getResponse();
		response.setHeader("Access-Control-Allow-Origin", "*");
		try {
			SimpleDateFormat bartDateFormat = new SimpleDateFormat
	  				("yyyy-MM-dd"); 
			Date date = new Date(); 
			System.out.println(bartDateFormat.format(date)); 
			Long newUserCount = identityService.NewSongCount(bartDateFormat.format(date));
			ResponseJsonUtils.json(response,newUserCount);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return NONE;
	}
	
	public String SongCountAll(){
		HttpServletResponse response = ServletActionContext.getResponse();
		response.setHeader("Access-Control-Allow-Origin", "*");
		try {
			Long SongCountAll = identityService.SongCountAll();
			ResponseJsonUtils.json(response,SongCountAll);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return NONE;
	}
	
	public String QrcodeCountAll(){
		HttpServletResponse response = ServletActionContext.getResponse();
		response.setHeader("Access-Control-Allow-Origin", "*");
		try {
			Long QrcodeCountAll = identityService.QrcodeCountAll();
			ResponseJsonUtils.json(response,QrcodeCountAll);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return NONE;
	}
	
	public String DownloadCountAll(){
		HttpServletResponse response = ServletActionContext.getResponse();
		response.setHeader("Access-Control-Allow-Origin", "*");
		try {
			Long DownloadCountAll = identityService.DownloadCountAll();
			ResponseJsonUtils.json(response,DownloadCountAll);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return NONE;
	}
	
	public String SystemParameter(){
		HttpServletResponse response = ServletActionContext.getResponse();
		response.setHeader("Access-Control-Allow-Origin", "*");
		try {
			InetAddress addr = InetAddress.getLocalHost();
			Properties props = System.getProperties();
			Runtime r = Runtime.getRuntime();
			Sigar sigar = SigarUtil.getInstance();
			String ip = addr.getHostAddress();//ip地址
			CpuInfo[] infos = sigar.getCpuInfoList();
			CpuInfo info = infos[0]; 
			String version =  props.getProperty("java.vm.specification.version");
			String arch = props.getProperty("os.arch");
			String versions =props.getProperty("os.version");
			 info.getMhz();
			/*CpuPerc cpu = sigar.getCpuPerc();
			System.out.println(String.valueOf(cpu.getCombined()));*/
		} catch (Exception e) {
			e.printStackTrace();
		}
		return NONE;
	}
	
}
